import 'dart:io';

void main() {
  bool lightsOn = false;
  int thermostat = 24;
  bool securityArmed = false;

  const int minTemp = 15;
  const int maxTemp = 30;

  while (true) {
    print("\nWelcome to the Smart Home System!");
    print("Please choose an action:");
    print("1. Toggle lights");
    print("2. Set thermostat temperature");
    print("3. Arm/disarm security system");
    print("4. View system status");
    print("5. Exit");

    stdout.write("Enter your choice: ");
    String? choice = stdin.readLineSync();

    switch (choice) {
      case '1':
        lightsOn = !lightsOn;
        print("Lights are now ${lightsOn ? 'ON' : 'OFF'}.");
        break;

      case '2':
        stdout.write("Set thermostat temperature ($minTemp°C – $maxTemp°C): ");
        int? temp = int.tryParse(stdin.readLineSync() ?? '');
        if (temp == null || temp < minTemp || temp > maxTemp) {
          print("Invalid temperature! Please enter a value between $minTemp and $maxTemp.");
        } else {
          thermostat = temp;
          print("Thermostat set to $thermostat°C.");
          if (thermostat % 3 == 0 && thermostat % 5 == 0) {
            print("Perfect Day");
          } else if (thermostat % 3 == 0) {
            print("Cool Day");
          } else if (thermostat % 5 == 0) {
            print("Warm Day");
          }
        }
        break;

      case '3':
        securityArmed = !securityArmed;
        print("Security system is now ${securityArmed ? 'ARMED' : 'DISARMED'}.");
        break;

      case '4':
        print("\nSystem Status:");
        print("- Lights: ${lightsOn ? 'ON' : 'OFF'}");
        print("- Thermostat: $thermostat°C - ${getTemperatureDescription(thermostat)}");
        print("- Security System: ${securityArmed ? 'ARMED' : 'DISARMED'}");
        break;

      case '5':
        print("Exiting the system. Goodbye!");
        return;

      default:
        print("Invalid choice! Please enter a number from 1 to 5.");
    }
  }
}

String getTemperatureDescription(int temp) {
  if (temp % 3 == 0 && temp % 5 == 0) return "Perfect Day";
  if (temp % 3 == 0) return "Cool Day";
  if (temp % 5 == 0) return "Warm Day";
  return "Normal";
}


